package com.baseframe.tool.utils.data;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;

public class FunUtil {

    /**
     * 空的
     * @return
     */
    public static<T> boolean isEmpty(T entity){

        if (entity == null) {
            return true;
        } else if (entity instanceof Optional) {
            return !((Optional<?>)entity).isPresent();
        } else if (entity instanceof CharSequence) {
            return ((CharSequence)entity).length() == 0;
        } else if (entity.getClass().isArray()) {
            return Array.getLength(entity) == 0;
        } else if (entity instanceof Collection) {
            return ((Collection<?>)entity).isEmpty();
        } else {
            return entity instanceof Map && ((Map<?, ?>) entity).isEmpty();
        }

    }

    public static <T> boolean isNotEmpty(T entity){

        return !isEmpty(entity);
    }
}
